Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
schematized
Advanced tools
Turn objects into JSON schemas! The more examples you provide, the better your schema will be.
Turn objects into JSON schemas! The more examples you provide, the better your schema will be.
A Node port of the Python module GenSON but with more inferred constraints.
Example use case: Generate JSON schemas using your API tests, then use the schemas to validate. To keep up to date, Write a test that compares your current schema with the generated schema. Then when your API changes, just update the tests with the newly generated schemas and move on with your day.
yarn add schematized
import SchemaBuilder from 'schematized' // Typescript & ESM
const { default: SchemaBuilder } = require('schematized') // CommonJS
const builder = new SchemaBuilder()
// Consume JSON
builder.addObject({
token: '74aea1a53d68b77e4f1f55fa90a7eb81',
role: ['Basic'],
})
// Produce JSON Schemas!
const schema = builder.toPrettySchema()
...
builder.addObject({
token: 'Bearer 6498d9afc96d1d8d881a2b7ded4f9290',
role: [
'Admin',
'Basic',
'Publisher'
]
})
...
builder.addSchema({
title: '/user server response',
description: '/user server response'
})
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"token": {
"type": "string",
"maxLength": 32,
"minLength": 32
},
"role": {
"type": "array",
"items": {
"type": "string",
"maxLength": 5,
"minLength": 5
}
}
},
"required": [
"role",
"token"
],
"additionalProperties": false,
"maxProperties": 2,
"minProperties": 2
}
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"token": {
"type": "string",
"maxLength": 39,
"minLength": 32
},
"role": {
"type": "array",
"items": {
"type": "string",
"maxLength": 9,
"minLength": 5
}
}
},
"required": [
"role",
"token"
],
"additionalProperties": false,
"maxProperties": 2,
"minProperties": 2
}
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "/user server response",
"description": "/user server response",
"type": "object",
"properties": {
"token": {
"type": "string",
"maxLength": 39,
"minLength": 32
},
"role": {
"type": "array",
"items": {
"type": "string",
"maxLength": 9,
"minLength": 5
}
}
},
"required": [
"role",
"token"
],
"additionalProperties": false,
"maxProperties": 2,
"minProperties": 2
}
Method | Definition | Parameter |
---|---|---|
.addObject($object) | Add an example to improve the generated schema. | Valid JSON object |
.addSchema($schema) | Add schemas to improve the generated schema. | Valid JSON Schema |
.toSchema() | Generate the schema. | None |
.toPrettySchema() | Generate the schema and pretty print. | None |
Visit the official JSON Schema site for specification details.
Type | Supported |
---|---|
String | Yes |
Number | Yes |
Integer | Never |
Object | Yes |
Array | Yes |
Tuple | Not yet |
Boolean | Yes |
Null | Yes |
Constraint | addSchema() | addObject() |
---|---|---|
title | Yes | Never |
description | Yes | Never |
$comment | Yes | Never |
default | Not yet | Not yet |
examples | Not yet | Not yet |
enum | Not yet | Not yet |
const | Not yet | Not yet |
anyOf | Yes | Yes |
allOf | Not yet | Not yet |
oneOf | Not yet | Not yet |
not | Not yet | Not yet |
if/then/else | Not yet | Not yet |
Constraint | addSchema() | addObject() |
---|---|---|
maxLength | Yes | Yes |
minLength | Yes | Yes |
format | Yes | Yes |
pattern | Not yet | Not yet |
contentMediaType | Not yet | Not yet |
contentEncoding | Not yet | Not yet |
Format | Supported? |
---|---|
date-time | Yes |
date | Yes |
time | Yes |
Yes | |
hostname | Not yet |
idn-hostname | Not yet |
ipv4 | Yes |
ipv6 | Yes |
uri | Yes |
uri-reference | Not yet |
url | Yes |
uuid | Yes |
iri | Not yet |
iri-reference | Not yet |
uri-template | Not yet |
json-pointer | Not yet |
relative-json-pointer | Not yet |
regex | Not yet |
Constraint | addSchema() | addObject() |
---|---|---|
maximum | Yes | Yes |
minimum | Yes | Yes |
exclusiveMaximum | Not yet | Not yet |
exclusiveMinimum | Not yet | Not yet |
multiple | Not yet | Not yet |
Constraint | addSchema() | addObject() |
---|---|---|
propertyPatterns | Yes | Yes |
additionalProperties | Yes | Yes |
required | Yes | Yes |
maxProperties | Yes | Yes |
minProperties | Yes | Yes |
Constraint | addSchema() | addObject() |
---|---|---|
maxItems | Not yet | Not yet |
minItems | Not yet | Not yet |
uniqueItems | Not yet | Not yet |
FAQs
Turn objects into JSON schemas! The more examples you provide, the better your schema will be.
The npm package schematized receives a total of 1 weekly downloads. As such, schematized popularity was classified as not popular.
We found that schematized demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.